 
 	<?php
		function set_val($obj, $val, $return='echo')
		{
			if(isset($obj))
				if(isset($obj->$val))
					if($return=='echo')
						echo($obj->$val);
					else
						return $obj->$val;
		}
	?>
 
 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.css"> <!--  -->
 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.filter.css"> <!--  -->

<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.min.js"></script>
<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.filter.js"></script>

				<div><br>
					<form id="form" class="block-content form" action="<?php echo site_url('flag/save')?>" method="post">
						<input type="hidden" id="id" name="id" value="<?php set_val($flag,'id')?>" />
						<div class="_100">
							<p><label for="name_ar">Arabic Flag Name</label>
							<input id="name_ar" name="name_ar" class="required" type="text" value="<?php set_val($flag,'name_ar')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="name_en">English Flag Name</label>
							<input id="name_en" name="name_en" class="required" type="text" value="<?php set_val($flag,'name_en')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="parent">Parent Flag</label>
							<select name="parent" id="parent" class="required">
								<option value="">:: Select Parent ::</option>
								<option value="0" <?php if(0==@$flag->parent) echo 'selected="selected"';?>><span style="color:red">(ROOT)</span> No Parent </option>
								<?php foreach($flags as $row):?>
									<option <?php if(set_val($flag,'parent','return')==$row->id) echo 'selected="selected"';?> value="<?php echo $row->id?>"><?php echo $row->name_ar?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						
						
						

						<div class="clear"></div>
						<div class="block-actions">
							<ul class="actions-left">
								<li><a class="button red" id="reset-validate-form" href="javascript:void(0);">Reset</a></li>
							</ul>
							<ul class="actions-right">
								<li><input type="submit" class="button" value="Save!"></li>
							</ul>
						</div>
					</form>

				</div>
				
				
	<script type="text/javascript">
						
		
	$().ready(function() {
		
		$("#parent").multiselect({
		   multiple: false,
		   header: "Select an option",
		   noneSelectedText: "Select an Option",
		   selectedList: 1,
		   position: {
			  my: 'left bottom',
			  at: 'left top'
		   },
		   maxWidth: 300,
		   show: "slide",
		   hide: "slide"

		}).multiselectfilter();
		
		
		/** Submit Form **/
		$("#form").validate({
				rules:{},
				messages: {},
				submitHandler: function(form) {
				   //submit
				$.post("<?php echo site_url('flag/save')?>", $("#form").serialize(),
					function(data){
						if(data){
							
							newdata = $.parseJSON(data);
							
							if(newdata.error){
								Gtheme = 'error';
								
								$.each(newdata.msg, function(index) {
									$.jGrowl(newdata.msg[index], { theme: Gtheme,position:'center'  });
								});

							}
							else{
								Gtheme = 'saved';
								$.jGrowl(newdata.msg, { theme: Gtheme,position:'center'  });
								$('.a-z-list').parent().children('.block-content').slideToggle();
								a_z_list();
								temp_id = $("#id").val();
								//clear the folrm
									$("#id").val('');
									$(":input").not(":button, :submit, :reset, :hidden").each(function () {
										this.value = '';
									});
								load_form(temp_id);
							}

						}
						else{
							$.jGrowl("Error!", { theme: 'error' });
						}
					});
				}
			});
		/** End Submit Form **/
		
		});
		
		
    </script>

